//询问是否跳转至登录页
const inquiryToLogin = () => {
	return new Promise ((resolve, reject) => {
		if(uni.getStorageSync('token')) {
			resolve(uni.getStorageSync('token'));
		}else {
			uni.showModal({
				title: '提示', content: '登录过时，是否立即跳转登录？',
				confirmColor: '#64aeb4',
				success:res => {
					if (res.confirm) uni.navigateTo({ url: '/pages/personalCenter/login' })
				}
			})
		}
	})
}

/**
 * 获取日期，如：2022-12-09
 * @param {String} type:返回加或减去多少的时间
 * @param {Number} data:时间戳
 * @param {Boolean} notYear:若传 true 则不要年份
 */
const dateLimit = (type, data, notYear) => {
	let date = '',
		showStr = '';
	if(data) {
		date = data;
	}else {
		date = new Date();
	}
	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let day = date.getDate();
	if (type === 'start') {
		year = year + 0;
	} else if (type === 'end') {
		// year = year + 1;
		// month = month + 1;
		day = day + 7;
	} else if(type === 'oldYear1') {
		year = year - 1;
	}
	month = month > 9 ? month : '0' + month;
	day = day > 9 ? day : '0' + day;
	if(notYear) {
		showStr = `${month}.${day}`;
	}else {
		showStr = `${year}-${month}-${day}`;
	}
	return showStr;
}

export {
	inquiryToLogin, dateLimit
}